$('.btn-forget').click(function () {
    $("#msg-tips").attr("style", "visibility:visible;color:#FF6633;");//显示div
    // $("#msg-tips").html("jQuery!");
    // $("#msg-tips").attr("style","visibility:hidden;");//隐藏div

    // var token = $.cookie('scj_token');
    // var user = $.cookie('scj_user');

    // var token =localStorage.getItem("scj_token");
    // var userString =localStorage.getItem("scj_user");
    // var user = JSON.parse(userString);
    // $("#msg-tips").html(user.id+ '  ' + token + ' ' + user.email);

});

$('.btn-forget2').click(function () {
    // $("#msg-tips").attr("style", "visibility:visible;color:#FF6633;");//显示div
    // var token = $.cookie('scj_token');
    // var user = $.cookie('scj_user');
    // $("#msg-tips").html("token:"+token+"<br>user.id:"+user.id);

    // var token = '测试1';
    // var user = '12345';
    // $.cookie('scj_token',token);
    // $.cookie('scj_user',user);

    // localStorage.setItem("scj_token", token );
    // localStorage.setItem("scj_user", user );

});

function showTips(data) {
    $("#msg-tips").attr("style", "visibility:visible;color:#FF6633;");//显示div
    $("#msg-tips").html(data);
}

$(function () {
    var $form = $('#form-with-tooltip');
    var $tooltip = $('<div id="vld-tooltip">提示信息！</div>');
    $tooltip.appendTo(document.body);
    $form.validator();
    var validator = $form.data('amui.validator');

    $form.on('focusin focusout', '.am-form-error input', function (e) {
        if (e.type === 'focusin') {
            var $this = $(this);
            var offset = $this.offset();
            var msg = $this.data('foolishMsg') || validator.getValidationMessage($this.data('validity'));

            $tooltip.text(msg).show().css({
                left: offset.left + 10,
                top: offset.top + $(this).outerHeight() + 10
            });
        } else {
            $tooltip.hide();
        }
    });
    ///输入框失去焦点的时候，检查是否需要隐藏提示
    $("input").blur(function () {
        if (!validator.valid) {
            $tooltip.hide();
        }
    });

});

//点击登录的时候的一个动效
$('.btn-loading-example').click(function () {
    var $btn = $(this)
    $btn.button('loading');

    var host = 'http://scj.web.co';
    var url = host + '/api/login/maillogin';
    var email = $(" input[ id='doc-vld-email-2-0' ] ").val();
    var pwd = $(" input[ id='doc-vld-pwd-1-0' ] ").val();

    // showTips(pwd);
    $.post(url, {email: email, pwd: pwd}, function (data) {
        if (data != null && data.code != null) {
            if (data.code == 200) {
                //按钮样式还原
                $btn.button('reset');
                //提示登录成功
                // showTips('登录成功！');
                //保存用户信息
                var token = data.data.token;
                var user = data.data.user;
                var userString = JSON.stringify(user);

                localStorage.setItem("scj_token", token );
                localStorage.setItem("scj_user", userString);

                $.cookie('scj_token',token);
                $.cookie('scj_user',userString);
                // console.log(user);
                // console.log(user.id);
                //跳转主页
                $(window).attr('location',host+'/index/index/user');

            } else {
                showTips(data.msg);
                $btn.button('reset');
            }
        }
    },"json").error(function (error) {
        $btn.button('reset');
        console.log(error);
    });

    // setTimeout(function(){
    //
    // }, 5000);
});


